//
//  KLStatusTopView.swift
//  BCWeiBo
//
//  Created by bcmac3 on 16/4/5.
//  Copyright © 2016年 KellenYangs. All rights reserved.
//

import UIKit

class KLStatusTopView: UIView {
    var status: KLStatus?{
        didSet{
            // 昵称
            nameLabel.text = status!.user!.name
            // 设置头像
            if let url = status?.user?.imageURL {
                iconView.sd_setImageWithURL(url)
            }
            // 设置认证图标
            verifiedView.image = status?.user?.verified_img
            // 设置会员图标
            vipView.image = status?.user?.memberImage
            // 设置来源
            sourceLabel.text = status?.source
            // 设置时间
            timeLabel.text = status?.created_at
            
        }
    }
    override init(frame: CGRect) {
        super.init(frame: frame)
        
        setupUI()
    }
    
    required init?(coder aDecoder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }
    
    private func setupUI(){
        // 1.添加子控件
        addSubview(headerView)
        addSubview(iconView)
        addSubview(verifiedView)
        addSubview(nameLabel)
        addSubview(vipView)
        addSubview(timeLabel)
        addSubview(sourceLabel)
        
        
        // 2.布局子控件
        let width = UIScreen.mainScreen().bounds.size.width
        headerView.xmg_AlignInner(type: XMG_AlignType.TopLeft, referView: self, size: CGSize(width: width, height: 10))
        
        // 头像
        iconView.xmg_AlignVertical(type: XMG_AlignType.BottomLeft, referView: headerView, size: CGSize(width: 35, height: 35), offset: CGPoint(x: 10, y: 10))
        
        // 认证图标
        verifiedView.xmg_AlignInner(type: XMG_AlignType.BottomRight, referView: iconView, size: nil, offset: CGPoint(x: 5, y: 5))
        
        // 昵称
        nameLabel.xmg_AlignHorizontal(type: XMG_AlignType.TopRight, referView: iconView, size: nil, offset: CGPoint(x: 10, y: 0))
        
        // 会员图标
        vipView.xmg_AlignHorizontal(type: XMG_AlignType.TopRight, referView: nameLabel, size: nil, offset: CGPoint(x: 10, y: 0))
        
        // 时间
        timeLabel.xmg_AlignHorizontal(type: XMG_AlignType.BottomRight, referView: iconView, size: nil, offset: CGPoint(x: 10, y: 0))
        
        // 来源
        sourceLabel.xmg_AlignHorizontal(type: XMG_AlignType.TopRight, referView: timeLabel, size: nil, offset: CGPoint(x: 10, y: 0))
    }
    
    // MARK: - 懒加载
    /// 顶部视图
    private lazy var headerView: UIView = {
        let view = UIView()
        view.backgroundColor = UIColor.darkGrayColor()
        return view
    }()
    
    /// 头像
    var iconView: UIImageView = UIImageView(image: UIImage(named: "avatar_default_big"))
    /// 认证图标
    private var verifiedView: UIImageView = UIImageView(image: UIImage(named: "avatar_enterprise_vip"))
    /// 昵称
    private var nameLabel: UILabel = UILabel(color: UIColor.darkGrayColor(), fontSize: 14)
    /// 会员图标
    private var vipView: UIImageView = UIImageView(image:  UIImage(named: "common_icon_membership"))
    /// 时间
    private var timeLabel: UILabel = UILabel(color: UIColor.orangeColor(), fontSize: 10)
    /// 来源
    private var sourceLabel: UILabel = UILabel(color: UIColor.darkGrayColor(), fontSize: 10)}
